// pages/webview/webview.js
Page({
  data: {
    url: ''
  },

  onLoad: function(options) {
    // 获取传入的URL参数
    if (options.url) {
      const decodedUrl = decodeURIComponent(options.url);
      this.setData({
        url: decodedUrl
      });
      
      // 设置导航栏标题
      wx.setNavigationBarTitle({
        title: ''
      });
    } else {
      wx.showToast({
        title: '无效的网址',
        icon: 'error'
      });
      setTimeout(() => {
        wx.navigateBack();
      }, 1500);
    }
  },

  onWebViewLoad: function(e) {
    console.log('网页加载完成');
  },

  onError: function(e) {
    console.error('网页加载失败:', e);
    wx.showModal({
      title: '加载失败',
      content: '网页加载失败，请检查网络连接或网址是否正确',
      showCancel: false,
      success: () => {
        wx.navigateBack();
      }
    });
  },

  onMessage: function(e) {
    console.log('收到网页消息:', e);
  },

  onShareAppMessage: function() {
    return {
      title: '分享网页',
      path: `/pages/webview/webview?url=${encodeURIComponent(this.data.url)}`
    };
  }
});